Skip to content

fix(agent-context): save ai_skills before re-registering extensions on init --force - #5323

Open
sx4im wants to merge 4 commits into
github:mainfrom
sx4im:fix-5321-init-force-extension-order
Open

sx4im wants to merge 4 commits into
github:mainfrom
sx4im:fix-5321-init-force-extension-order

Conversation

@sx4im

@sx4im sx4im commented Nov 9, 2026

Copy link
Copy Markdown

Fixes #5321

What broke

specify init --here --force into a skills-mode agent re-registered installed extensions before init-options.json recorded ai_skills, so the extension manager rendered command files instead of SKILL.md files.

What changed

src/specify_cli/command_init.py: save the init options (including the ai_skills flag) right after setup() and before the force re-registration, instead of after the shared-infra and workflow steps. The block moved verbatim; all its inputs are already resolved at that point.

How verified

  • New regression test test_init_force_registers_extensions_as_skills_in_skills_mode fails on main and passes with the fix: after a force re-init into copilot, the extension SKILL.md exists and no command file is written.
  • tests/specify_cli/test_command_init.py 25/25, extension skills + upgrade + bundles suites 187/187, integration generic/cli suites 318/318.
  • ruff check (0.15.0, the CI version) clean on both changed files.
  • Honest limits: the fix touches no platform-branched code, so no Windows-specific verification was needed; Windows pytest proof awaits CI. Only the init/extension/integration suites ran locally, not the full suite.

…n init --force

`specify init --here --force` into a skills-mode agent re-registered
installed extensions before init-options.json recorded ai_skills, so
the extension manager rendered command files instead of SKILL.md
files. Save the init options right after setup() and before the
force re-registration; the block moved verbatim and all its inputs
are already resolved at that point.

Fixes github#5321
@sx4im
sx4im requested a review from mnriem as a code owner November 9, 2026 01:39
Copilot AI adaptive review requested due to automatic review settings November 9, 2026 01:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Forced re-initialization can follow symlinked extension skill directories and overwrite SKILL.md files outside the project, requiring destination-ancestor checks and regression coverage.

1 open issue
What changed in this PR

Fixes #5321 by saving init options before forced extension re-registration, so extensions use the selected agent’s skills mode.

Changes:

  • Moves the existing options-save block immediately after integration setup.
  • Adds a regression test confirming force re-init creates an extension SKILL.md without a command-mode file.
File Description
tests/​specify_cli/​test_command_init.py Tests extension skill registration during forced Copilot re-init.
src/​specify_cli/​command_init.py Persists agent and skills-mode options before extension registration.

Review effort: Balanced (auto)

Comment thread src/specify_cli/command_init.py Resolved
…ration

Forced extension skill registration bypasses the pre-existing-directory
guards, so a skill directory that is a symlink to a location outside
the project would receive the generated SKILL.md. Validate the skill
destination against its trusted root before any write, reusing the
shared-infrastructure check that already guards skill removal, and
skip destinations outside any trusted root.

Adds a regression test: a forced re-init with a symlinked extension
skill directory writes nothing outside the project.
Copilot AI adaptive review requested due to automatic review settings November 9, 2026 02:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Relative project roots can silently skip extension skills, forced registration can modify hard-linked files, and an unguarded symlink test can fail on Windows without symlink privileges.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Prevent forced registration from overwriting hard-linked skill files

src/​specify_cli/​extensions/​__init__.py:1640

The new directory check does not reject an existing hard-linked SKILL.md; forced registration still writes it in place, changing every file linked to the same data. Saving skills options earlier makes this path reachable during force re-init even without previous skills options. Protect the file write as well, by rejecting multiply linked destinations or replacing them without modifying the existing file's data, and add regression coverage.

AI-generated review: GitHub Copilot for the requesting reviewer (identity not supplied; model unknown; automated mode; fully AI-generated).

Review effort: Balanced (auto)

Comment thread src/specify_cli/extensions/__init__.py Resolved
Comment thread tests/specify_cli/test_command_init.py Resolved
… SKILL.md on forced registration

Copilot review on github#5323 found three follow-ups to the symlinked-destination fix: relative project roots failed trusted-root validation and silently skipped skills, an existing hard-linked SKILL.md was rewritten in place, and the symlink regression test failed on Windows without symlink privileges.
Copilot AI adaptive review requested due to automatic review settings November 9, 2026 03:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A failed hard-link detachment still allows an in-place write, which can unintentionally modify other hard-linked copies; the error path must stop the write and have test coverage.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

High severity Do not overwrite hard-linked files when detaching fails

src/​specify_cli/​extensions/​__init__.py:1743

If detaching the hard link raises OSError, this handler still reaches write_text, which uses an in-place Path.write_text. For example, a writable file in a non-writable directory can be overwritten even though it cannot be unlinked, so other hard-linked copies are still modified—the behavior this guard is intended to prevent. Skip the skill or propagate the error rather than proceeding, and add coverage for a failed detach.

AI-generated review for the requester by GitHub Copilot (model unknown; automated mode; code-review analysis).

2 resolved since last review

Review effort: Balanced (auto)

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 9, 2026
@mnriem

mnriem commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

…egistration

A failed hard-link detach still fell through to the in-place write, so a
writable SKILL.md in a non-writable directory was overwritten through the
surviving link and every linked copy changed. Skip the skill instead and
leave the file untouched; the init itself still succeeds.

Adds a regression test that fails the detach and checks both the linked
copy outside the project and the project skill keep their old content.
Copilot AI adaptive review requested due to automatic review settings November 9, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed to assess unpublished findings involving a critical Windows junction overwrite risk and incomplete skill registration during generic force-init.

1 open issue

Review effort: Balanced (auto)

@mnriem

mnriem commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

@sx4im

sx4im commented Nov 10, 2026

Copy link
Copy Markdown
Author

All of the Copilot feedback here is already addressed on this branch:

  • Symlinked skill destinations are rejected before any write, in 56b903c.
  • Relative project roots are normalized to an absolute path before validation in 7d09da6, so skills are no longer silently skipped, and the symlink test now skips on Windows accounts without symlink privileges.
  • A failed hard-link detach now skips the skill instead of writing through it, in ae748e5.

The later Copilot review links back to the same symlink finding, which 56b903c already covers.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The destination validator still accepts in-root Windows directory junctions, allowing forced extension registration to overwrite another directory’s existing SKILL.md.

1 open issue
1 resolved since last review

Review effort: Balanced (auto)

Comment on lines +1644 to +1646
_validate_safe_shared_directory(
trusted_root, Path(os.path.abspath(skill_subdir))
)
@mnriem

mnriem commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback. If not applicable, please explain why

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

init --force registers extensions before ai_skills is saved (skills-mode init writes command files)

3 participants